package com.itheima.blog.admin.controller;


import com.itheima.blog.admin.aop.MyLog;
import com.itheima.blog.admin.entity.TWebNavbar;
import com.itheima.blog.admin.service.ITWebNavbarService;
import com.itheima.common.domain.PageReqDto;
import com.itheima.common.domain.PageResDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 门户网站首页导航栏 前端控制器
 * </p>
 *
 * @author blog
 * @since 2023-07-11
 */
@RestController
@RequestMapping("/index/route")
@Api(tags = "门户管理之导航栏管理")
@RequiredArgsConstructor
@Validated
public class TWebNavbarController {

    private final ITWebNavbarService webNavbarService;

    @ApiOperation("新增导航栏管理")
    @PostMapping
    public void addRoute(@RequestBody TWebNavbar tWebNavbar){
        webNavbarService.addRoute(tWebNavbar);
    }

    @MyLog(value = "修改导航栏管理")
    @ApiOperation("修改导航栏管理")
    @PostMapping("/{routeId}")
    public void updateByRouteId(@PathVariable("routeId") Long routeId, @RequestBody TWebNavbar tWebNavbar){
        tWebNavbar.setId(Math.toIntExact(routeId));
        webNavbarService.updateByRouteId(tWebNavbar);
    }

    @MyLog(value = "删除导航栏管理")
    @ApiOperation("删除导航栏管理")
    @DeleteMapping
    public void deleteRoute(Long id){
        webNavbarService.deleteRoute(id);
    }

    @ApiOperation("导航栏列表展示")
    @GetMapping("/list")
    public PageResDto<TWebNavbar> findRouteList(PageReqDto pageReqDto){
        return webNavbarService.findRouteList(pageReqDto);
    }

}